/**********************************************************************************
 * Code license:  GNU General Public License v3                                   *
 * Main page:     https://code.google.com/p/library-cross-platform/               *
 * Issue tracker: https://code.google.com/p/library-cross-platform/issues/list    *
***********************************************************************************/

package library.compiler;

import java.io.*;
import java.util.*;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class DirectoryList {

  List        directoryList = new ArrayList();

  public DirectoryList() {
  }

  public void add(java.lang.String dir) {
    if(isInList(dir) == false)
     directoryList.add(dir);
  }
  
  public void clear() {
    directoryList.clear();
  }

  protected boolean isInList(java.lang.String dir) {
    ListIterator it        = directoryList.listIterator();
    boolean      ret_value = false;
    while(it.hasNext()) {
      if(dir.equals((java.lang.String)it.next())) {
        ret_value = true;
        break;
      }       
    }
    return ret_value;
  }

  public java.lang.String isPresentFile(java.lang.String file) {
   ListIterator it           = directoryList.listIterator();
   File         files[]      = null;
   Filter       filter       = new Filter();
   filter.setFileFilter(file);
   while(it.hasNext()) {
    java.lang.String s = (java.lang.String)it.next();
    files = new File(s).listFiles(filter);
    if(files.length > 0)
     return files[0].getAbsolutePath();    
   }	  
    return null;
  }

  protected class Filter implements FileFilter  
  {
	java.lang.String filter;
    public void setFileFilter(java.lang.String f) {
      filter = f;
    }
      public boolean accept(File file) {  
         return file.getName().equalsIgnoreCase(filter);  
      }  
   }  
}
